package com.example.sprintboot_demo1.controller;

import com.example.sprintboot_demo1.config.SxtProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController // 简化写法，等同于 @Controller + @ResponseBody
public class HelloController {

    @Value("${email}")
    private String email;

    @Value("${my1email}")
    private String my1email;

    @Value("${city1[0]}") // 获取city1数组的第一个元素
    private String city1;

    private final SxtProperties sxtProperties;

    public HelloController(SxtProperties sxtProperties) {
        this.sxtProperties = sxtProperties;
    }

    @RequestMapping("/hello")
    public String hello() {
        return "Hello";
    }

    @RequestMapping("/getValue")
    public String getValue() {
        return "email: " + email + "\n" +
                "my1email: " + my1email + "\n" +
                "city1: " + city1 + "\n" +
                "mobile: " + (sxtProperties.getSxt() != null && !sxtProperties.getSxt().isEmpty() ? sxtProperties.getSxt().get(0).getMobile() : "N/A");
    }
}
